package com.ruijie.autotest.log.common.crypto;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class AESSha1Algorithm implements Algorithm {
	@Override
	public SecretKey createSecretKey(String password) {
		try {
			byte[] passwordAsBytes = password.getBytes();
			KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
			SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
			secureRandom.setSeed(passwordAsBytes);
			keyGenerator.init(256, secureRandom);
			return keyGenerator.generateKey();
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException("failed to create SecretKey.", e);
		}
	}

	@Override
	public String algorithm() {
		return "AES";
	}
}
